import type { FC, PropsWithChildren } from "react";

import styles from "@/views/auth/css/auth-layout.module.less";

import useAppStore, { selectToken } from "@/store/app-store";
import { Navigate } from "react-router-dom";

const AuthLayout: FC<PropsWithChildren> = ({ children }) => {
  // 基于 Selector 选取派生的数据
  const token = useAppStore(selectToken);

  if (token) {
    // 有 token，已登录
    return <Navigate to="/" replace />;
  }
  return (
    <div className={styles.container}>
      <div className={styles.boxTest}>{children}</div>
    </div>
  );
};

export default AuthLayout;
